package cn.e3.sso.controller;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.e3.sso.service.TokenService;
import cn.e3.utils.E3Result;
import cn.e3.utils.JsonUtils;
/*
 * 根据taken获得user
 */
@Controller
public class TokenController {
	@Autowired
	private TokenService tokenService;
	@RequestMapping(value="/user/token/{token}",produces="application/json;charset=utf-8")
	@ResponseBody//jsonp改造
	public String getUserByToken(@PathVariable String token,String callback){
		E3Result e3Result = tokenService.getUserByToken(token);
		if(StringUtils.isNotBlank(callback)){
			//callback是判断是否为跨域请求的标记，有callback,jquery会自动封装方法
			return callback+"("+JsonUtils.objectToJson(e3Result)+");";
		}
		return JsonUtils.objectToJson(e3Result);
	}
}
